﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using ZedGraph;
using System.Threading;

namespace Config
{
    public partial class WaveForm : Form
    {
        private const int N = 480000;
        String[] x = new String[N];
        double[] hx = new double[N];
        double[] hy = new double[N];
        double[] hz = new double[N];
        double[] ex = new double[N];
        double[] ey = new double[N];
        public delegate void MyInvoke();//线程相关


        public  WaveForm()
        {
            InitializeComponent();
            Thread thread = new Thread(new ThreadStart(DoWork));
            thread.Start();
            
        }

        public void UpdateForm()
        {
            DrawCurve1();
            DrawCurve2();
            DrawCurve3();
            DrawCurve4();
            DrawCurve5();
            System.Console.WriteLine(x[1]);
        }
        public void DoWork()
        {
            MyInvoke mi = new MyInvoke(UpdateForm);
            StreamReader sr = new StreamReader(new FileStream("test.txt ", FileMode.Open, FileAccess.Read));
            int k;
            string s;
            int len;
            for (k = 0; k < N; k++)
            {
                // x[k] = k;
                string str = sr.ReadLine();

                string[] sArray = Regex.Split(str, " ", RegexOptions.IgnoreCase);
                int j = 0;
                double[] data = new double[30];
                foreach (string i in sArray)
                {
                    string trim = i.Trim();
                    if (trim.Length != 0)
                    {
                        data[j] = Convert.ToDouble(trim);
                        j++;
                    }

                }

                hx[k] = data[6];
                hy[k] = data[7];
                hz[k] = data[8];
                ex[k] = data[13];
                ey[k] = data[14];
                s = data[5].ToString();
                len = s.Length;
                x[k] = data[1].ToString().PadLeft(2, '0') + "月" + data[2].ToString().PadLeft(2, '0') +"日"+ data[3].ToString().PadLeft(2, '0') + ":" + data[4].ToString().PadLeft(2, '0') + ":" + s.PadLeft(2, '0');
                //x中装的为时间字符串
                //s.Substring(0, s.Length - 1); 
            }
            sr.Close();
            this.BeginInvoke(mi);
            

        }
       
        private void DrawCurve1()
        {
            ZedGraphControl zgc = new ZedGraphControl();
            GraphPane myPane = zgc.GraphPane;
            myPane.Title.Text = "Hx";
            myPane.XAxis.Title.Text = "x";
            myPane.YAxis.Title.Text = "Hx";
            myPane.Border = new Border(Color.Gray, 2.0F);

            //添加X轴、Y轴的数据到面板上，但是由于AddCurve方法没有匹配的参数，所以第二个X轴想显示         
            //时间数据时，要先设置为null，然后在下面单独添加。
            LineItem myCurve = myPane.AddCurve("", null, hx, Color.Red, SymbolType.Default);
            myPane.XAxis.Type = AxisType.Text;
            myPane.XAxis.Scale.TextLabels = x;//添加日期到X轴
            zgc.AxisChange();
            zedGraphControl1.Controls.Clear();
            zedGraphControl1.Controls.Add(zgc);
            zgc.Width = this.Width;
            zgc.Height = this.Height;
            zgc.Dock = DockStyle.Fill;
            zgc.IsShowHScrollBar = true;//横向滚动条
            //zgc.IsAutoScrollRange = true;
            myPane.YAxis.MajorGrid.IsVisible = true ;
            myPane.XAxis.MajorGrid.IsVisible = true;
            
        }
        private void DrawCurve2()
        {
            ZedGraphControl zgc = new ZedGraphControl();
            GraphPane myPane = zgc.GraphPane;
            myPane.Title.Text = "Hy";
            myPane.XAxis.Title.Text = "x";
            myPane.YAxis.Title.Text = "Hy";
            myPane.Border = new Border(Color.Gray, 2.0F);

            //添加X轴、Y轴的数据到面板上，但是由于AddCurve方法没有匹配的参数，所以第二个X轴想显示         
            //时间数据时，要先设置为null，然后在下面单独添加。
            LineItem myCurve = myPane.AddCurve("", null, hy, Color.Red, SymbolType.Default);
            myPane.XAxis.Type = AxisType.Text;
            myPane.XAxis.Scale.TextLabels = x;//添加日期到X轴
            zgc.AxisChange();
            zedGraphControl2.Controls.Clear();
            zedGraphControl2.Controls.Add(zgc);
            zgc.Width = this.Width;
            zgc.Height = this.Height;
            zgc.Dock = DockStyle.Fill;
            zgc.IsShowHScrollBar = true;//横向滚动条
            zgc.IsAutoScrollRange = true;
            myPane.YAxis.MajorGrid.IsVisible = true;
            myPane.XAxis.MajorGrid.IsVisible = true;
        }
        private void DrawCurve3()
        {
            ZedGraphControl zgc = new ZedGraphControl();
            GraphPane myPane = zgc.GraphPane;
            myPane.Title.Text = "Hz";
            myPane.XAxis.Title.Text = "x";
            myPane.YAxis.Title.Text = "Hz";
            myPane.Border = new Border(Color.Gray, 2.0F);

            //添加X轴、Y轴的数据到面板上，但是由于AddCurve方法没有匹配的参数，所以第二个X轴想显示         
            //时间数据时，要先设置为null，然后在下面单独添加。
            LineItem myCurve = myPane.AddCurve("", null, hz, Color.Red, SymbolType.Default);
            myPane.XAxis.Type = AxisType.Text;
            myPane.XAxis.Scale.TextLabels = x;//添加日期到X轴
            zgc.AxisChange();
            zedGraphControl3.Controls.Clear();
            zedGraphControl3.Controls.Add(zgc);
            zgc.Width = this.Width;
            zgc.Height = this.Height;
            zgc.Dock = DockStyle.Fill;
            zgc.IsShowHScrollBar = true;//横向滚动条
            zgc.IsAutoScrollRange = true;
            myPane.YAxis.MajorGrid.IsVisible = true;
            myPane.XAxis.MajorGrid.IsVisible = true;
        }
        private void DrawCurve4()
        {
            ZedGraphControl zgc = new ZedGraphControl();
            GraphPane myPane = zgc.GraphPane;
            myPane.Title.Text = "Ex";
            myPane.XAxis.Title.Text = "x";
            myPane.YAxis.Title.Text = "Ex";
            myPane.Border = new Border(Color.Gray, 2.0F);

            //添加X轴、Y轴的数据到面板上，但是由于AddCurve方法没有匹配的参数，所以第二个X轴想显示         
            //时间数据时，要先设置为null，然后在下面单独添加。
            LineItem myCurve = myPane.AddCurve("", null, ex, Color.Red, SymbolType.Default);
            myPane.XAxis.Type = AxisType.Text;
            myPane.XAxis.Scale.TextLabels = x;//添加日期到X轴
            zgc.AxisChange();
            zedGraphControl4.Controls.Clear();
            zedGraphControl4.Controls.Add(zgc);
            zgc.Width = this.Width;
            zgc.Height = this.Height;
            zgc.Dock = DockStyle.Fill;
            zgc.IsShowHScrollBar = true;//横向滚动条
            zgc.IsAutoScrollRange = true;
            myPane.YAxis.MajorGrid.IsVisible = true;
            myPane.XAxis.MajorGrid.IsVisible = true;

        }
        private void DrawCurve5()
        {
            ZedGraphControl zgc = new ZedGraphControl();
            GraphPane myPane = zgc.GraphPane;
            myPane.Title.Text = "Ey";
            myPane.XAxis.Title.Text = "x";
            myPane.YAxis.Title.Text = "Ey";
            myPane.Border = new Border(Color.Gray, 2.0F);

            //添加X轴、Y轴的数据到面板上，但是由于AddCurve方法没有匹配的参数，所以第二个X轴想显示         
            //时间数据时，要先设置为null，然后在下面单独添加。
            LineItem myCurve = myPane.AddCurve("", null, ey, Color.Red, SymbolType.Default);
            myPane.XAxis.Type = AxisType.Text;
            myPane.XAxis.Scale.TextLabels = x;//添加日期到X轴
            zgc.AxisChange();
            zedGraphControl5.Controls.Clear();
            zedGraphControl5.Controls.Add(zgc);
            zgc.Width = this.Width;
            zgc.Height = this.Height;
            zgc.Dock = DockStyle.Fill;
            zgc.IsShowHScrollBar = true;//横向滚动条
            zgc.IsAutoScrollRange = true;
            myPane.YAxis.MajorGrid.IsVisible = true;
            myPane.XAxis.MajorGrid.IsVisible = true;

        }
        

        


        

    }
}
